<template>
  <el-col class="app-v-center app-column" style="overflow: auto;">
    <el-row class="app-h-64px app-fill-width app-v-center" :gutter="10">
      <div class="px-2">
        <el-input v-model="search.title" placeholder="请输入标题搜索" />
      </div>
      <div class="pr-2">
        <el-select v-model="search.status" placeholder="问题状态">
          <el-option label="未解决" :value="0" />
          <el-option label="已解决" :value="1" />
        </el-select>
      </div>
      <div class="pr-2">
        <el-button size="mini" type="info" @click="getDataList">
          搜索
        </el-button>
      </div>
    </el-row>
    <el-table
      :data="dataList"
      class="app-flex-1"
      style="width: 100%;overflow-y: auto;"
    >
      <el-table-column
        prop="userName"
        align="center"
        label="账号"
        width="180"
      />
      <el-table-column
        prop="avatar"
        align="center"
        label="头像"
      >
        <template slot-scope="scope">
          <div v-if="scope.row.avatar">
            <img style="width: 75px;height: 75px;" :src="scope.row.avatar" alt="">
          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="title"
        align="center"
        label="标题"
        width="180"
      />

      <el-table-column
        prop="cover"
        align="center"
        label="封面"
      >
        <template slot-scope="scope">
          <div v-if="scope.row.cover">
            <img style="width: 75px;height: 75px;" :src="scope.row.cover" alt="">
          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="money"
        align="center"
        label="答金"
        width="180"
      />
      <el-table-column
        prop="urgent"
        align="center"
        label="加急"
      >
        <template slot-scope="scope">
          {{ scope.row.urgent === 1 ? '是': '否' }}
        </template>
      </el-table-column>
      <el-table-column
        prop="original"
        align="center"
        label="原创"
      >
        <template slot-scope="scope">
          {{ scope.row.original === 1 ? '是': '否' }}
        </template>
      </el-table-column>
      <el-table-column
        prop="commercial"
        align="center"
        label="可商用"
      >
        <template slot-scope="scope">
          {{ scope.row.commercial === 1 ? '是': '否' }}
        </template>
      </el-table-column>
      <el-table-column
        prop="erchuang"
        align="center"
        label="可二创"
      >
        <template slot-scope="scope">
          {{ scope.row.erchuang === 1 ? '是': '否' }}
        </template>
      </el-table-column>
      <el-table-column
        prop="questionCollectCount"
        align="center"
        label="收藏数"
        width="100"
      />
      <el-table-column
        prop="questionLikeCount"
        align="center"
        label="点赞数"
        width="100"
      />
      <el-table-column
        prop="readingVolume"
        align="center"
        label="浏览量"
        width="100"
      />
      <el-table-column
        align="center"
        width="200"
        label="操作"
      >
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            @click="handleEdit(scope.$index, scope.row)"
          >编辑</el-button> -->
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      class="mb-10 mt-5"
      background
      :current-page.sync="pageNo"
      :page-sizes="[10, 20, 50]"
      :page-size.sync="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="getDataList"
      @current-change="getDataList"
    />
  </el-col>
</template>

<script>
import { getQuestionList,deleteQuestionById } from '@/api/question'
export default {
  data: () => ({
    dataList: [],
    pageNo: 1,
    pageSize: 10,
    total: 0,
    form: {
      name: '',
      mobile: '',
      username: '',
      password: '123456',
      roleId: null,
      roleName: '',
      userId: null
    },
    search: {
      status: 0,
      title: ''
    }
  }),
  mounted() {
    this.getDataList()
  },
  methods: {
    getDataList() {
      const params = {
        pageNo: this.pageNo,
        pageSize: this.pageSize,
        title: this.search.title ?? undefined,
        status: this.search.status ?? undefined
      }
      getQuestionList(params).then(res => {
        if (res.code === 200) {
          this.dataList = res.data.dataList
          this.total = res.data.total
        }
      })
    },
    handleEdit(index,row) {
      this.isEdit = true
      this.form = row
      delete this.form.password
      this.addUserDialog = true
    },
    handleDelete(index,row) {
      this.$confirm(`确认删除该问题？`,'提示',{
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteQuestionById({ id: row.id }).then(res => {
          if (res.code === 200) {
            this.$message({ type: 'success',message: '已删除' })
            this.pageNo = 1
            this.getDataList()
          }
        })
      }).catch(() => {
        this.$message('已取消')
      })
    }
  }
}
</script>
